package com.ruoyi.web.controller.weiriya;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.weiriya.domain.WMemberChargeRecord;
import com.ruoyi.weiriya.service.IWMemberChargeRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 用户充电记录Controller
 * 
 * @author lynn
 * @date 2023-08-01
 */
@Api(tags = "用户充电记录管理")
@RestController
@RequestMapping("/weiriya/chargeRecord")
public class WMemberChargeRecordController extends BaseController
{
    @Autowired
    private IWMemberChargeRecordService wMemberChargeRecordService;

    /**
     * 查询用户充电记录列表
     */
    @ApiOperation("获取用户充电记录列表")
    @PreAuthorize("@ss.hasPermi('weiriya:chargeRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(WMemberChargeRecord wMemberChargeRecord)
    {
        startPage();
        List<WMemberChargeRecord> list = wMemberChargeRecordService.getList(wMemberChargeRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户充电记录列表
     */
    @ApiOperation("导出用户充电记录列表")
    @PreAuthorize("@ss.hasPermi('weiriya:chargeRecord:export')")
    @Log(title = "用户充电记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WMemberChargeRecord wMemberChargeRecord)
    {
        List<WMemberChargeRecord> list = wMemberChargeRecordService.getList(wMemberChargeRecord);
        ExcelUtil<WMemberChargeRecord> util = new ExcelUtil<WMemberChargeRecord>(WMemberChargeRecord.class);
        util.exportExcel(response, list, "用户充电记录数据");
    }

    /**
     * 导入用户充电记录列表
     */
    @ApiOperation("导入用户充电记录列表")
    @PreAuthorize("@ss.hasPermi('weiriya:chargeRecord:import')")
    @Log(title = "用户充电记录", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<WMemberChargeRecord> util = new ExcelUtil<WMemberChargeRecord>(WMemberChargeRecord.class);
        List<WMemberChargeRecord> list = util.importExcel(file.getInputStream());
        return success(wMemberChargeRecordService.saveBatch(list));
    }

    /**
     * 获取用户充电记录详细信息
     */
    @ApiOperation("获取用户充电记录详细")
    @ApiImplicitParam(name = "id", value = "用户充电记录ID", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:chargeRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(wMemberChargeRecordService.getWMemberChargeRecordById(id));
    }

    /**
     * 新增用户充电记录
     */
    @ApiOperation("开始充电（新增用户充电记录）")
    @PreAuthorize("@ss.hasPermi('weiriya:chargeRecord:add')")
    @Log(title = "用户充电记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WMemberChargeRecord wMemberChargeRecord)
    {
        return toAjax(wMemberChargeRecordService.saveWMemberChargeRecord(wMemberChargeRecord));
    }

    /**
     * 查看一拖十充电桩状态
     */
    @ApiOperation("查看一拖十充电桩状态")
    @PreAuthorize("@ss.hasPermi('weiriya:chargeRecord:add')")
    @PostMapping("/detail/charger")
    public AjaxResult detailCharger(@RequestBody WMemberChargeRecord wMemberChargeRecord)
    {
        return success(wMemberChargeRecordService.detailCharger(wMemberChargeRecord));
    }
    /**
     * 查看一拖十充电桩状态
     */
    @ApiOperation("查看一拖十充电桩状态")
    @PreAuthorize("@ss.hasPermi('weiriya:chargeRecord:add')")
    @PostMapping("/socketTwoDetail/charger")
    public AjaxResult socketTwoDetailCharger(@RequestBody WMemberChargeRecord wMemberChargeRecord)
    {
        return success(wMemberChargeRecordService.socketTwoDetailCharger(wMemberChargeRecord));
    }

    /**
     * 修改用户充电记录
     */
    @ApiOperation("手动结束充电（更新用户充电记录）")
    @PreAuthorize("@ss.hasPermi('weiriya:chargeRecord:edit')")
    @Log(title = "用户充电记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WMemberChargeRecord wMemberChargeRecord)
    {
        return toAjax(wMemberChargeRecordService.updateWMemberChargeRecordById(wMemberChargeRecord));
    }

    /**
     * 删除用户充电记录
     */
    @ApiOperation("删除用户充电记录")
    @ApiImplicitParam(name = "ids", value = "用户充电记录ID集合", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('weiriya:chargeRecord:remove')")
    @Log(title = "用户充电记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(wMemberChargeRecordService.removeByIds(ids));
    }
}
